package com.example.a2048game

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.example.a2048game.databinding.ActivityMainBinding
import com.example.a2048game.diy.Card
import com.example.a2048game.diy.GameView

class MainActivity : AppCompatActivity() {

    private lateinit var mainBinding: ActivityMainBinding
    private val gameView: GameView by lazy {
        findViewById<GameView>(R.id.gameView)
    }
    private val tvScore: TextView by lazy {
        findViewById<TextView>(R.id.tvScore)
    }

    private var score = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mainBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mainBinding.root)

        mainBinding.gameView.setMainActivity(this)

        mainBinding.regame.setOnClickListener {
            gameView.startGame()
        }
    }

    fun showScore(){
        tvScore.text = score.toString()
    }
    fun clearScore(){
        score = 0
        showScore()
    }
    fun addScore(num:Int){
        score += num
        showScore()
    }

    fun getScore():Int{
        return score
    }


}